Skip to content

Fix MixedType->equals(ErrorType) #3934

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jul 17, 2025
Merged

Fix MixedType->equals(ErrorType) #3934

merged 13 commits into from
Jul 17, 2025

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Apr 13, 2025

@staabm
Copy link
Contributor Author

staabm commented Apr 13, 2025

I was not sure whether TemplateMixedType should be considered equal to MixedType or not

@staabm staabm marked this pull request as draft April 13, 2025 20:37
@staabm staabm marked this pull request as ready for review April 14, 2025 07:45
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

@herndlm
Copy link
Contributor

herndlm commented Apr 14, 2025

👍 I suppose this improves the weird cases I had before too, where error is accepted as a mixed or at least something like that 😊

@@ -4489,7 +4489,7 @@ public function addTypeToExpression(Expr $expr, Type $type): self

if ($originalExprType->equals($nativeType)) {
$newType = TypeCombinator::intersect($type, $originalExprType);
if ($newType->isConstantScalarValue()->yes() && $newType->equals($originalExprType)) {
if ($newType->isObject()->no() && $newType->equals($originalExprType)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will look into whether we can get rid of the isObject() check here today

Copy link
Contributor Author

@staabm staabm May 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I looked into it. I think we cannot drop the $newType->isObject()->no() check here, because Objects will be considered equal by ObjectType->equals() even though they have slight differences which are important when narrowing, e.g.

new Foo() in local-scope vs. Foo typed variable (implicit Final)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

most conservative move would be to leave it $newType->isConstantScalarValue()->yes() until we get a slow case which benefits from the change and only fix MixedType->equals(ErrorType) for now

@staabm
Copy link
Contributor Author

staabm commented May 16, 2025

just reduced it to the actual bugfix.

@ondrejmirtes ondrejmirtes merged commit ed7eb47 into phpstan:2.1.x Jul 17, 2025
419 of 420 checks passed
@ondrejmirtes
Copy link
Member

Thank you.

@staabm staabm deleted the equals branch July 17, 2025 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants